package com.yequan.leetcode.trie;

/**
 * @author : Administrator
 * @date : 2020/5/1
 */
public class TrieNode {

    private TrieNode[] links;

    /**
     * 字典树每一个节点对应字母表长度为 字母表长度
     */
    private final int capacity = 26;

    private boolean isEnd = false;

    public TrieNode() {
        links = new TrieNode[capacity];
    }

    /**
     * 判断该节点是否包含该字符
     *
     * @return
     */
    public boolean containsKey(char ch) {
        return links[ch - 'a'] != null;
    }

    /**
     * 获取对应的下层节点
     *
     * @param ch
     * @return
     */
    public TrieNode getTrieNode(char ch) {
        return links[ch - 'a'];
    }

    /**
     * 插入下层节点
     *
     * @param ch
     * @param trieNode
     */
    public void put(char ch, TrieNode trieNode) {
        links[ch - 'a'] = trieNode;
    }

    /**
     * 设置结尾
     */
    public void setEnd() {
        isEnd = true;
    }

    /**
     * 获取是否结束
     *
     * @return
     */
    public boolean isEnd() {
        return isEnd;
    }

}
